package event

type Type string

type Event interface {
	Type() Type
	Get(key string) interface{}
	Set(key string, val interface{})
	GetAll() map[string]interface{}
	SetAll(data map[string]interface{})
}

type BaseEvent struct {
	typ  Type
	data map[string]interface{}
}

func (e *BaseEvent) Type() Type {
	return e.typ
}

func (e *BaseEvent) Get(key string) interface{} {
	if e.data == nil {
		return nil
	}
	return e.data[key]
}

func (e *BaseEvent) Set(key string, val interface{}) {
	if e.data == nil {
		e.data = map[string]interface{}{}
	}
	e.data[key] = val
}

func (e *BaseEvent) GetAll() map[string]interface{} {
	return e.data
}

func (e *BaseEvent) SetAll(data map[string]interface{}) {
	e.data = data
}

func NewBase(typ Type, data ...map[string]interface{}) Event {
	e :=  &BaseEvent{
		typ: typ,
	}
	if len(data) > 0 {
		e.data = data[0]
	}
	return e
}
